/*********************************************************************************
 *      Copyright:  (C) 2023 LXC
 *                  All rights reserved.
 *
 *       Filename:  get_time.c
 *    Description:  This file get device time.
 *                 
 *        Version:  1.0.0(08/05/23)
 *         Author:  Lin XinCheng <1481155734@qq.com>
 *      ChangeLog:  1, Release initial version on "08/05/23 16:48:22"
 *                 
 ********************************************************************************/
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>

#include "logger.h"

int get_time(char *getttime)
{
	if ( NULL == getttime )
	{
		LOGGER_ERROR("Invalid input argument");
		return -1;
	}

	time_t			 sec = 0;
	struct tm		 ptm;	
	struct tm		*rv = NULL;	
	
	time(&sec);				

	rv = localtime_r(&sec, &ptm);

	if ( NULL == &ptm )
	{
		LOGGER_ERROR("NULL pointer: &resulte");
		return -1;
	}

	strftime(getttime, 32, "%Y-%m-%d %H:%M:%S", &ptm);
	LOGGER_DEBUG("get_time successfully: %s", getttime);
	
	return 0;
}